package com.cskaoyan.mall.controller.admin;

import com.cskaoyan.mall.bean.Order;
import com.cskaoyan.mall.bean.bo.OrderListBO;
import com.cskaoyan.mall.bean.bo.OrderShipBO;
import com.cskaoyan.mall.bean.vo.GeneralItemsBean;
import com.cskaoyan.mall.bean.vo.OrderDetailVO;
import com.cskaoyan.mall.bean.vo.ResultVO;
import com.cskaoyan.mall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: dyj
 * @Date: 2021/1/10 21:57
 * @Description
 */
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public ResultVO list(OrderListBO orderListBO){
        GeneralItemsBean generalItemsBean = orderService.getOrderList(orderListBO);
        return ResultVO.ok(generalItemsBean);
    }

    @RequestMapping("detail")
    public ResultVO detail(Integer id){
        OrderDetailVO orderDetailVO = orderService.queryOrderDetail(id);
        return ResultVO.ok(orderDetailVO);
    }

    // map 接收两个参数 orderId 订单id refundMoney 退款金额
    @RequestMapping("refund")
    public ResultVO refund(@RequestBody Map map){
        int rows  = orderService.refund(map);

        if(rows == 0){
            return ResultVO.error(621,"订单退款失败");
        }

        return ResultVO.ok();
    }

    @RequestMapping("ship")
    public ResultVO ship(@RequestBody OrderShipBO orderShipBO){
        int rows = orderService.OrderShip(orderShipBO);

        if(rows == 0){
            return ResultVO.error(621,"订单发货失败");
        }

        return ResultVO.ok();
    }


}
